<% 
  	/**
	 * workoutsCreateWorkout.jsp
	 * 
	 * This is basically a blank page which is used to create a workout object
	 * and set it as a session variable for further modification. 
	 *
	 * The third page of a sequence of forms requisitioning the user for the information about their workout.
	 * The complete sequence is:
	 * workoutsCalendar.jsp -- Gets date
	 * workouts.jsp -- Gets information common between workout types: userID, prescribed, and type
	 * workoutsCreateWorkout.jsp -- redirect dummy page, creates the actual workout object and puts in the fields 
	 * 	we've already gotten from the user
	 * workoutsAMRAP.jsp/workoutsTimed.jsp/workoutsTabata.jsp -- Gets the type-specific workout information
	 * workoutsCreateWorkoutTyped.jsp -- redirect dummy page, adds the typed information to our Workout object
	 * workoutsAddExercise.jsp -- Allows the user to select individual exercises and append them to the list in our
			exercise.
	 * workoutsCreateExercise.jsp -- redirect dummy page, adds the exercise to our Workout object
	 * workoutsSubmit.jsp -- final page, submits the fully created workout to the database
	 *
	 * @author Chris
	 */
%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   	pageEncoding="ISO-8859-1"%>
<%@page import="b1w1nn1ng.crossf1t.db.*"%>
<%@page import="b1w1nn1ng.crossf1t.gui.*"%>
<%@page import="b1w1nn1ng.crossf1t.business.*"%>
<%@page import="java.util.*" %>

<% 
	User user = (User) session.getAttribute("user");
	session.setAttribute("user", user);
	
	Calendar cal = Calendar.getInstance();
	cal.setTime(CalendarDisplay.stringToDate(request.getParameter("date")));
	boolean prescribed = !(request.getParameter("prescribed") == null);
	
	Workout wo;
	if(request.getParameter("type").equals("amrap")) {
		wo = new AMRAP(user.getId(), prescribed, cal);
		session.setAttribute("curWorkout", wo);
		response.sendRedirect("workoutsAMRAP.jsp");
	} else if(request.getParameter("type").equals("tabata")) {
		wo = new Tabata(user.getId(), prescribed, cal);
		session.setAttribute("curWorkout", wo);
		response.sendRedirect("workoutsTabata.jsp");
	} else if (request.getParameter("type").equals("timed")) {
		wo = new Timed(user.getId(), prescribed, cal);
		session.setAttribute("curWorkout", wo);
		response.sendRedirect("workoutsTimed.jsp");
	} else {
		System.err.println("You broke workoutsCreateWorkout.jsp");
	}
%>
